package com.yuetong.business.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import com.yuetong.common.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import com.yuetong.business.domain.YtElevatorModels;
import com.yuetong.business.mapper.YtElevatorBrandsMapper;
import com.yuetong.business.domain.YtElevatorBrands;
import com.yuetong.business.service.IYtElevatorBrandsService;

/**
 * 电梯品牌管理Service业务层处理
 * 
 * @author  卓晓君
 * @date 2025-03-08
 */
@Service
public class YtElevatorBrandsServiceImpl implements IYtElevatorBrandsService 
{
    @Autowired
    private YtElevatorBrandsMapper ytElevatorBrandsMapper;

    @Override
    public int getElevatorBrandsTotal() {
        return  ytElevatorBrandsMapper.selectYtElevatorBrandsCount();
    }



    /**
     * 查询电梯品牌管理
     * 
     * @param brandId 电梯品牌管理主键
     * @return 电梯品牌管理
     */
    @Override
    public YtElevatorBrands selectYtElevatorBrandsByBrandId(Long brandId)
    {
        return ytElevatorBrandsMapper.selectYtElevatorBrandsByBrandId(brandId);
    }

    /**
     * 查询电梯品牌管理列表
     * 
     * @param ytElevatorBrands 电梯品牌管理
     * @return 电梯品牌管理
     */
    @Override
    public List<YtElevatorBrands> selectYtElevatorBrandsList(YtElevatorBrands ytElevatorBrands)
    {
        return ytElevatorBrandsMapper.selectYtElevatorBrandsList(ytElevatorBrands);
    }

    /**
     * 新增电梯品牌管理
     * 
     * @param ytElevatorBrands 电梯品牌管理
     * @return 结果
     */
    @Transactional
    @Override
    public int insertYtElevatorBrands(YtElevatorBrands ytElevatorBrands)
    {
        int rows = ytElevatorBrandsMapper.insertYtElevatorBrands(ytElevatorBrands);
        insertYtElevatorModels(ytElevatorBrands);
        return rows;
    }

    /**
     * 修改电梯品牌管理
     * 
     * @param ytElevatorBrands 电梯品牌管理
     * @return 结果
     */
    @Transactional
    @Override
    public int updateYtElevatorBrands(YtElevatorBrands ytElevatorBrands)
    {
        ytElevatorBrandsMapper.deleteYtElevatorModelsByBrandId(ytElevatorBrands.getBrandId());
        insertYtElevatorModels(ytElevatorBrands);
        return ytElevatorBrandsMapper.updateYtElevatorBrands(ytElevatorBrands);
    }

    /**
     * 批量删除电梯品牌管理
     * 
     * @param brandIds 需要删除的电梯品牌管理主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteYtElevatorBrandsByBrandIds(Long[] brandIds)
    {
        ytElevatorBrandsMapper.deleteYtElevatorModelsByBrandIds(brandIds);
        return ytElevatorBrandsMapper.deleteYtElevatorBrandsByBrandIds(brandIds);
    }

    /**
     * 删除电梯品牌管理信息
     * 
     * @param brandId 电梯品牌管理主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteYtElevatorBrandsByBrandId(Long brandId)
    {
        ytElevatorBrandsMapper.deleteYtElevatorModelsByBrandId(brandId);
        return ytElevatorBrandsMapper.deleteYtElevatorBrandsByBrandId(brandId);
    }



    /**
     * 新增电梯型号管理信息
     * 
     * @param ytElevatorBrands 电梯品牌管理对象
     */
    public void insertYtElevatorModels(YtElevatorBrands ytElevatorBrands)
    {
        List<YtElevatorModels> ytElevatorModelsList = ytElevatorBrands.getYtElevatorModelsList();
        Long brandId = ytElevatorBrands.getBrandId();
        if (StringUtils.isNotNull(ytElevatorModelsList))
        {
            List<YtElevatorModels> list = new ArrayList<YtElevatorModels>();
            for (YtElevatorModels ytElevatorModels : ytElevatorModelsList)
            {
                ytElevatorModels.setBrandId(brandId);
                list.add(ytElevatorModels);
            }
            if (list.size() > 0)
            {
                ytElevatorBrandsMapper.batchYtElevatorModels(list);
            }
        }
    }
}
